From 52aed5d60744cadec2d6ae4cf86814e8851aa8ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Fri, 6 Jan 2017 09:43:52 +0100 Subject: [PATCH] Add gtk_widget_snapshot_child --- gtk/gtkboxgadget.c | 2 +- gtk/gtkwidget.c | 69 ++++++++++++++++++++++++++++++++++++++++++ gtk/gtkwidgetprivate.h | 5 +++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/gtk/gtkboxgadget.c b/gtk/gtkboxgadget.c index f331489b95..93d9d92d42 100644 --- a/gtk/gtkboxgadget.c +++ b/gtk/gtkboxgadget.c @@ -536,7 +536,7 @@ gtk_box_gadget_snapshot (GtkCssGadget *gadget, GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, draw_index); if (GTK_IS_WIDGET (child->object)) - gtk_container_snapshot_child (GTK_CONTAINER (owner), GTK_WIDGET (child->object), snapshot); + gtk_widget_snapshot_child (owner, GTK_WIDGET (child->object), snapshot); else gtk_css_gadget_snapshot (GTK_CSS_GADGET (child->object), snapshot); } diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index bbf5f3ca16..8bebdfb048 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -15735,3 +15735,72 @@ gtk_widget_forall (GtkWidget *widget, child = next; } } + +static void +gtk_widget_get_translation_to_child (GtkWidget *widget, + GtkWidget *child, + int *x_out, + int *y_out) +{ + GtkAllocation allocation; + GdkWindow *window, *w; + int x, y; + + /* translate coordinates. Ugly business, that. */ + if (!_gtk_widget_get_has_window (widget)) + { + _gtk_widget_get_allocation (widget, &allocation); + x = -allocation.x; + y = -allocation.y; + } + else + { + x = 0; + y = 0; + } + + window = _gtk_widget_get_window (widget); + + for (w = _gtk_widget_get_window (child); w && w != window; w = gdk_window_get_parent (w)) + { + int wx, wy; + gdk_window_get_position (w, &wx, &wy); + x += wx; + y += wy; + } + + if (w == NULL) + { + x = 0; + y = 0; + } + + if (!_gtk_widget_get_has_window (child)) + { + _gtk_widget_get_allocation (child, &allocation); + x += allocation.x; + y += allocation.y; + } + + *x_out = x; + *y_out = y; +} + +void +gtk_widget_snapshot_child (GtkWidget *widget, + GtkWidget *child, + GtkSnapshot *snapshot) +{ + int x, y; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (_gtk_widget_get_parent (child) == widget); + g_return_if_fail (snapshot != NULL); + + gtk_widget_get_translation_to_child (widget, child, &x, &y); + + gtk_snapshot_translate_2d (snapshot, x, y); + gtk_widget_snapshot (child, snapshot); + gtk_snapshot_translate_2d (snapshot, -x, -y); +} diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index c19dd2a966..d4da81c08e 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -304,6 +304,11 @@ void gtk_widget_forall (GtkWidget GtkCallback callback, gpointer user_data); +void gtk_widget_snapshot_child (GtkWidget *widget, + GtkWidget *child, + GtkSnapshot *snapshot); + + /* inline getters */ static inline gboolean -- 2.30.2